/*******************************************************************************************************

Figure A3: Petitions presented to the House of Commons, by sender type, before and
after the reform.

*******************************************************************************************************/


*Set directory path
cd "C:\Users\tsa23\Documents\petitions\replication files"

clear all
use dta\did_rep.dta

set scheme plotplainblind

sort ID year

collapse (sum) type* (sum) petitions*, by(treatperiod)


egen typeall = rowtotal(type1 type2 type3 type4 type5 type6 type7)


foreach j of numlist 1/7 { 
    gen type`j'share = 100*type`j'/typeall

}

keep  treatperiod type1share type2share type3share type4share type5share type6share
 
 gen typeA=.
  stack treatperiod type1share treatperiod type2share treatperiod type3share treatperiod type4share treatperiod type5share  treatperiod type6share, into(treatperiod typeA) wide
 
rename _stack typeno
 
gen period = "0"
replace period  = "Before" if treatperiod == 0
replace period  = "After" if treatperiod == 1

gen typename = "0"
replace typename  = "Religious" if typeno==1 
replace typename  = "Citizen" if typeno==2 
replace typename  = "Societies" if typeno==3 
replace typename  = "Local government" if typeno==4
replace typename  = "Transport" if typeno==6
replace typename  = "Business" if typeno==5
 

 graph hbar  typeA,   over(typename, label(labsize(small) )) over(period,  sort(1)  label(labsize(small))) blabel(bar, format(%2.1f) angle(90)) ytitle("Petition share")  asyvars intensity(25)  bargap(10) bar(1, lpattern(solid) color(grey) lwidth(0.25) ) bar(2, lpattern(dash) lwidth(0.25))  bar(3, lpattern(dot) lwidth(0.25)) bar(4, lpattern(dash_dot) lwidth(0.25)) bar(5, lpattern(longdash) lwidth(0.25)) bar(6, lpattern(shortdash) lwidth(0.25) )

graph export graphs\figureA3.pdf, as(pdf) name("Graph") replace
 